﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace browserplayform
{
    public partial class form_browser : Form
    {
        Hashtable _serviceTable = new Hashtable();

        public form_browser()
        {
            InitializeComponent();

            
        }

        private void form_browser_Load(object sender, EventArgs e)
        {
            //webkit
            //WebKit.WebKitBrowser webkit = new WebKit.WebKitBrowser();
            //webkit.Dock = DockStyle.Fill;
            //this.Controls.Add(webkit);
            //webkit.Navigate("http://127.0.0.1:8084/Metro/view/s01/fas/fas1.jsp");
            
        }

        //窗口平铺显示
        private void MenuItem_Layout_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void MenuItem_NewForm_Webkit_Click(object sender, EventArgs e)
        {
            try { 
                //webkitbrowser和cefsharp 的包有部分冲突 引用的时候只能使用其中一个
                string s_FormClassName = "browserplayform.webkitform";
                Form f_Service = null;
                f_Service = Activator.CreateInstance(Type.GetType(s_FormClassName)) as Form;
                this.AddService(f_Service);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void MenuItem_NewForm_Firefox_Click(object sender, EventArgs e)
        {
            try
            {
                string s_FormClassName = "browserplayform.firefoxform";
                Form f_Service = null;
                f_Service = Activator.CreateInstance(Type.GetType(s_FormClassName)) as Form;
                this.AddService(f_Service);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
}

        private void MenuItem_NewForm_Chrome_Click(object sender, EventArgs e)
        {

        }

        private void form_browser_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Visible = false;
        }

        private void form_browser_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
            Application.Exit();
        }

        public void AddService(Form ServiceForm)
        {
            ServiceForm.Show();
            ServiceForm.MdiParent = this;

            _serviceTable.Add(ServiceForm, DateTime.Now);
        }

        public void DelService(Form ServiceForm)
        {
            _serviceTable.Remove(ServiceForm);
        }

        private void MenuItem_NewForm_Webbrowser_Click(object sender, EventArgs e)
        {
            try
            {
                string s_FormClassName = "browserplayform.webbrowserform";
                Form f_Service = null;
                f_Service = Activator.CreateInstance(Type.GetType(s_FormClassName)) as Form;
                this.AddService(f_Service);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void MenuItem_NewForm_CefSharp_Click(object sender, EventArgs e)
        {
            try
            {
                string s_FormClassName = "browserplayform.cefsharpform";
                Form f_Service = null;
                f_Service = Activator.CreateInstance(Type.GetType(s_FormClassName)) as Form;
                this.AddService(f_Service);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
    }
}
